<?php

require_once( dirname(__FILE__).'/common.php' );
require_once( MMVCPATH.'dbg_util.php' );
require_once( MMVCPATH.'InputFilter.php' );

try {
	$tests = array(
		array('input'=>3, 'filter'=>'Int', 'result'=>3),
		array('input'=>2, 'filter'=>'IP', 'result'=>false),
		array('input'=>'127.0.0.1', 'filter'=>'IP', 'result'=>'127.0.0.1'),
		array('input'=>2, 'filter'=>'Int', 'result'=>2),
		array('input'=>0, 'filter'=>'Int', 'result'=>0),
		array('input'=>'0', 'filter'=>'Int', 'result'=>'0'),
		array('input'=>'', 'filter'=>'Int', 'result'=>''),
		array('input'=>'yes', 'filter'=>'Bool', 'result'=>1),
		array('input'=>'true', 'filter'=>'Bool', 'result'=>1),
		array('input'=>'1', 'filter'=>'Bool', 'result'=>1),
		array('input'=>'1', 'filter'=>'Bool', 'result'=>1),
		array('input'=>'0', 'filter'=>'Bool', 'result'=>0),
		array('input'=>0, 'filter'=>'Bool', 'result'=>0),
		array('input'=>'no', 'filter'=>'Bool', 'result'=>0),
		array('input'=>'false', 'filter'=>'Bool', 'result'=>0),
	);
	
	$filters = new \InputFilter();
	
	foreach ($tests as $t) {
		$k = 'random';
		if ( isset($t['key']) )
			$k = $t['key'];
		$res = call_user_func( array($filters,'filter'.$t['filter']), $t['input'] );
		check( $res === $t['result'], "Test failed (expected '{$t['result']}', got '$res'): ".str_replace("\n",' ',var_export($t,true)) );
	}
	
	echo basename(__FILE__,'.php').": OK\n";
}
catch ( Exception $e ) {
	check( false, $e );
}

?>